package climspace.ejb;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;
import climspace.hadoop.ArchiveStation;
import climspace.hadoop.ArchiveStationImpl;

@MessageDriven(activationConfig = {
		@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
		@ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/climspace/hdfs"),
		@ActivationConfigProperty(propertyName = "maxSession", propertyValue = "10") })
public class HistoricalDataMdb implements MessageListener {
	@Override
	public void onMessage(Message message) {

		try {
			MapMessage mapMessage = (MapMessage) message;
			String stationId = mapMessage.getString("stationId");
			String fromDate = mapMessage.getString("fromDate");
			String toDate = mapMessage.getString("toDate");
			String jobID = mapMessage.getString("jobID");

			// TODO ArchiveStation with default configurations
			ArchiveStation archiveStation = new ArchiveStationImpl();
			archiveStation.submitHistoricalDataJob(stationId, fromDate, toDate, jobID);
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}

}
